/*
 * Copyright (C) 2011 by Fabien Barbero
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.flickr.desktop.core;

import com.flickr.api.ApiKey;
import com.flickr.api.LocalCache;
import com.flickr.api.LocalCacheImpl;
import com.flickr.api.auth.AuthenticationService;
import com.flickr.api.auth.AuthenticationServiceImpl;
import com.flickr.api.galleries.GalleriesService;
import com.flickr.api.galleries.GalleriesServiceImpl;
import com.flickr.api.photosets.PhotosetsService;
import com.flickr.api.photosets.PhotosetsServiceImpl;
import com.flickr.desktop.core.bootstrap.Bootstrap;
import com.flickr.desktop.core.bootstrap.BootstrapImpl;
import com.flickr.desktop.core.config.FlickrConfiguration;
import com.flickr.desktop.core.error.ErrorDisplayer;
import com.flickr.desktop.core.error.ErrorManager;
import com.flickr.desktop.core.error.ErrorManagerImpl;
import com.flickr.desktop.core.exit.ExitService;
import com.flickr.desktop.core.exit.ExitServiceImpl;
import com.flickr.desktop.core.login.LoginService;
import com.flickr.desktop.core.login.LoginServiceImpl;
import com.flickr.desktop.gui.views.ErrorDisplayerViewImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import org.codeartisans.java.sos.messagebus.MessageBus;
import org.codeartisans.java.sos.messagebus.MultiThreadDeliveryMessageBus;
import org.codeartisans.java.sos.threading.DefaultWorkQueue;
import org.codeartisans.java.sos.threading.WorkQueue;

/**
 *
 * @author Fabien Barbero
 */
public class FlickrCoreModule extends AbstractModule {
    
    private final FlickrConfiguration config;
    private final ApiKey apiKey;
    
    public FlickrCoreModule(FlickrConfiguration config, ApiKey apiKey) {
        this.config = config;
        this.apiKey = apiKey;
    }

    @Override
    protected void configure() {
        bind(FlickrConfiguration.class).toInstance(config);
        bind(MessageBus.class).toInstance(new MultiThreadDeliveryMessageBus(new DefaultWorkQueue("Flickr-Bus", 6)));
        bind(WorkQueue.class).toInstance(new DefaultWorkQueue("Flickr", 6));
        
        bind(Bootstrap.class).to(BootstrapImpl.class).in(Singleton.class);
        bind(ErrorManager.class).to(ErrorManagerImpl.class).in(Singleton.class);
        bind(ErrorDisplayer.class).to(ErrorDisplayerViewImpl.class).in(Singleton.class);
        
        bind(LoginService.class).to(LoginServiceImpl.class).in(Singleton.class);
        bind(ExitService.class).to(ExitServiceImpl.class).in(Singleton.class);
        
        bind(ApiKey.class).toInstance(apiKey);
        bind(LocalCache.class).to(LocalCacheImpl.class).in(Singleton.class);
        bind(AuthenticationService.class).to(AuthenticationServiceImpl.class).in(Singleton.class);
        bind(GalleriesService.class).to(GalleriesServiceImpl.class).in(Singleton.class);
        bind(PhotosetsService.class).to(PhotosetsServiceImpl.class).in(Singleton.class);
    }
    
}
